﻿<phone:PhoneApplicationPage 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:con="clr-namespace:WinMilk.Gui.Controls" x:Name="phoneApplicationPage"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    x:Class="WinMilk.Gui.PivotLandingPage"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
    shell:SystemTray.IsVisible="True"
    con:TiltEffect.IsTiltEnabled="True"
    DataContext="{Binding RelativeSource={RelativeSource Self}}"
    Loaded="PhoneApplicationPage_Loaded">
    
    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <Grid x:Name="LayoutRoot">
        <controls:Pivot Title="{Binding Path=Loc.AppNameCaps, Source={StaticResource L10N}}" Name="Pivot">

            <!--Panorama item one-->
            <controls:PivotItem x:Name="TasksPanel" Header="{Binding Path=Loc.TasksHeader, Source={StaticResource L10N}}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <ScrollViewer>
                        <StackPanel>
                            <TextBlock x:Name="OverdueHeader" Text="{Binding Path=Loc.OverdueTasksHeader, Source={StaticResource L10N}}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Visibility="{Binding HasItems, Converter={StaticResource VisibilityConverter}, ElementName=OverdueList, Mode=OneWay}" />
                            <con:TaskListControl x:Name="OverdueList" ItemsSource="{Binding OverdueTasks}" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
                            <TextBlock x:Name="TodayHeader" Text="{Binding Path=Loc.TodayTasksHeader, Source={StaticResource L10N}}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Visibility="{Binding HasItems, Converter={StaticResource VisibilityConverter}, ElementName=TodayList, Mode=OneWay}" />
                            <con:TaskListControl x:Name="TodayList" ItemsSource="{Binding TodayTasks}" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
                            <TextBlock x:Name="TomorrowHeader" Text="{Binding Path=Loc.TomorrowTasksHeader, Source={StaticResource L10N}}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Visibility="{Binding HasItems, Converter={StaticResource VisibilityConverter}, ElementName=TomorrowList, Mode=OneWay}"/>
                            <con:TaskListControl x:Name="TomorrowList" ItemsSource="{Binding TomorrowTasks}" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
                            <TextBlock x:Name="WeekHeader" Text="{Binding Path=Loc.WeekTasksHeader, Source={StaticResource L10N}}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Visibility="{Binding HasItems, Converter={StaticResource VisibilityConverter}, ElementName=WeekList, Mode=OneWay}"/>
                            <con:TaskListControl x:Name="WeekList" ItemsSource="{Binding WeekTasks}" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
                            <TextBlock x:Name="NoDueHeader" Text="{Binding Path=Loc.NoDueTasksHeader, Source={StaticResource L10N}}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Visibility="{Binding HasItems, Converter={StaticResource VisibilityConverter}, ElementName=NoDueList, Mode=OneWay}"/>
                            <con:TaskListControl x:Name="NoDueList" ItemsSource="{Binding NoDueTasks}" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
                        </StackPanel>
                    </ScrollViewer>
                    <!--
                    <StackPanel HorizontalAlignment="Right" Margin="0,-101,0,0" Orientation="Horizontal" VerticalAlignment="Top" d:LayoutOverrides="HorizontalAlignment">
                        <con:BigIconButton Type="add" Text="" Click="AddTask_Click"/>
                        <con:BigIconButton Type="sync" Text="" Click="Sync_Click" />
                    </StackPanel>-->
                </Grid>
            </controls:PivotItem>

            <controls:PivotItem x:Name="ListsPanel" Header="{Binding Path=Loc.ListsHeader, Source={StaticResource L10N}}">
                <Grid>
                    <ListBox x:Name="ListsList" SelectionChanged="ListsList_SelectionChanged" ItemsSource="{Binding TaskLists}">
                        <ListBox.Resources>
                            <Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
                                <Setter Property="Background" Value="Transparent"/>
                                <Setter Property="BorderThickness" Value="0"/>
                                <Setter Property="BorderBrush" Value="Transparent"/>
                                <Setter Property="Padding" Value="0"/>
                                <Setter Property="HorizontalContentAlignment" Value="Left"/>
                                <Setter Property="VerticalContentAlignment" Value="Top"/>
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ListBoxItem">
                                            <Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
                                                <VisualStateManager.VisualStateGroups>
                                                    <VisualStateGroup x:Name="CommonStates">
                                                        <VisualState x:Name="Normal"/>
                                                        <VisualState x:Name="MouseOver"/>
                                                        <VisualState x:Name="Disabled">
                                                            <Storyboard>
                                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="LayoutRoot">
                                                                    <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/>
                                                                </ObjectAnimationUsingKeyFrames>
                                                                <DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ContentContainer"/>
                                                            </Storyboard>
                                                        </VisualState>
                                                    </VisualStateGroup>
                                                    <VisualStateGroup x:Name="SelectionStates">
                                                        <VisualState x:Name="Unselected"/>
                                                        <VisualState x:Name="Selected"/>
                                                    </VisualStateGroup>
                                                </VisualStateManager.VisualStateGroups>
                                                <ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{StaticResource PhoneForegroundBrush}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
                                            </Border>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ListBox.Resources>
                        <ListBox.ItemContainerStyle>
                            <StaticResource ResourceKey="ListBoxItemStyle"/>
                        </ListBox.ItemContainerStyle>

                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="410" Height="70" Margin="5" Background="{StaticResource PhoneChromeBrush}">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="10" />
                                        <ColumnDefinition Width="*" />
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="10" />
                                    </Grid.ColumnDefinitions>

                                    <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.ColumnSpan="4" Visibility="{Binding IsNormal, Converter={StaticResource VisibilityConverter}}">
                                        <Rectangle.Fill>
                                            <SolidColorBrush Color="{StaticResource PhoneChromeColor}" />
                                        </Rectangle.Fill>
                                    </Rectangle>

                                    <Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.ColumnSpan="4" Visibility="{Binding IsSmart, Converter={StaticResource VisibilityConverter}}">
                                        <Rectangle.Fill>
                                            <SolidColorBrush Color="{StaticResource PhoneAccentColor}" />
                                        </Rectangle.Fill>
                                    </Rectangle>

                                    <con:DynamicTextBlock Text="{Binding LocName}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Grid.Column="1" VerticalAlignment="Center" FontFamily="{StaticResource PhoneFontFamilyLight}" HorizontalAlignment="Left" />
                                    <TextBlock Text="{Binding Count}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Grid.Column="2" HorizontalAlignment="Right" VerticalAlignment="Center" Visibility="{Binding HasItems, Converter={StaticResource VisibilityConverter}}" />
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>
            </controls:PivotItem>

            <controls:PivotItem x:Name="TagsPanel" Header="{Binding Path=Loc.TagsHeader, Source={StaticResource L10N}}">
                <ListBox Name="TagsList" ItemsSource="{Binding Tags}" SelectionChanged="TagsList_SelectionChanged">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}" FontSize="{StaticResource PhoneFontSizeExtraLarge}" Margin="{StaticResource PhoneTouchTargetOverhang}" />
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PivotItem>
            
        </controls:Pivot>

        <con:AddTaskControl x:Name="AddTaskPopup" Submit="AddTaskPopup_Submit" Top="0"/>

        <ProgressBar IsIndeterminate="{Binding IsLoading}" 
                     Visibility="{Binding IsLoading, Converter={StaticResource VisibilityConverter}}" 
                     Height="10" 
                     VerticalAlignment="Top" 
                     Margin="0,137,0,0" 
                     Style="{StaticResource PerformanceProgressBar}"/>

    </Grid>
</phone:PhoneApplicationPage>